﻿using Hellang.Middleware.ProblemDetails;
using MyWebApi.Infrostructure;
using Serilog;
using Serilog.Events;
using Serilog.Exceptions;

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
    .Enrich.FromLogContext()
    .Enrich.WithProcessId()
    .Enrich.WithThreadId()
    .Enrich.WithExceptionDetails()
    .WriteTo.Async(c => c.Seq("http://localhost:5341"))
    .WriteTo.Async(c => c.Console())
    .CreateLogger();
try
{
    Log.Information("Start Web...");
    var builder = WebApplication.CreateBuilder(args);
    builder.Host.ConfigureHost();
    builder.Services.ConfigureServices(builder.Environment, builder.Configuration);

    var app = builder.Build();
    app.UseProblemDetails();
    app.UseSwagger();
    app.UseSwaggerUI();

    app.UseCors("CorsPolicy");
    app.UseHttpsRedirection();

    app.UseAuthorization();

    app.MapControllers();

    app.Run();
}
catch (Exception ex)
{
    Log.Error(ex, "Error to start");
}
finally
{
    Log.CloseAndFlush();
}
